import turtle as t
import math as m

bg = t.Screen()
t.ht()
t.speed(0)
t.tracer(0)
prase = 0
score = 0
uplevel_list = [1,6,7,12]
r = 50
x = 0
y = 0
gravity = 2
xv = 0
yv = 0
prase_check = 0
rx = 0
ry = 0
rlength = 0
rwidth = 0
rangle = 0
rxv = 0
ryv = 0
if_blocked = 0 #0represents no blocking,1 blocked by rec

def check_prase():
    global score
    global prase
    global uplevel_list
    if score in uplevel_list:
        prase = 1+uplevel_list.index(score)
def draw_circle(m,n,o):
    t.pu()
    if if_blocked == 0:
        t.goto(m,n-o)
        t.pd()
        t.circle(o)
    else:
        if rangle%90 == 0:
            pass
    t.pu()
def draw_rectangular(x,y,length,
					 width,angle):
	t.pu()
	t.goto(x,y)
	t.setheading(angle)
	t.backward(length/2)
	t.right(90)
	t.forward(width/2)
	t.left(90)
	t.pd()
	for a in range(2):
		for i in [length,width]:
			t.forward(i)
			t.left(90)
	t.pu()
	t.setheading(0)
def loop():	
    global r
    global x
    global y
    global gravity
    global xv
    global yv
    global prase_check
    global rx
    global ry
    global rlength
    global rwidth
    global rangle
    global rxv
    global ryv
    if prase == 0:
        x = 0
        y = 0
        draw_circle(x,y,r)
    elif prase == 1:
		if not prase_check == prase:
			prase_check = prase
			yv = 15
			xv = 7
		yv -= gravity
		x += xv
		y += yv
		if y < -200:
			yv *= -1
			yv += gravity
		if abs(x) > 200:
			xv *= -1
		draw_circle(x,y,r)
    elif prase == 2:
		t.goto(0,0)
		t.write('You W    N!',align='center',font=('Arial',80,'normal'))
		t.pensize(4)
		x = 98
		y = 37
		r = 38
		draw_circle(x,y,r)
		t.pensize(1)
    elif prase == 3:
        t.goto(0,0)
        t.write('Well, you haven\'t.',
				align='center',font=('Arial',16,'normal'))
        if not prase_check == prase:
			yv = 30
			y += yv
			if y >= 500:
				prase_check=prase
				rlength=1200
				rwidth=900
				x=0
				y=500
				yv=0
				r=50
				if_blocked = 1
        else:
			rlength -= (rlength-400)*0.2
			rwidth -= (rwidth-300)*0.2
			draw_rectangular(rx,ry,rlength,
							 rwidth,rangle)
			yv -= gravity
			y += yv
			if y <= -100:
				y = -100
				yv *= -0.8
        draw_circle(x,y,r)
def detect_click(mx,my):
	global score
	if (mx-x)**2+(my-y)**2 <= r**2:
		score += 1
def show_score():
    if not prase == 0:
        t.goto(0,200)
        t.write(str(score),
				align='center',font=('Arial',16,'normal'))

while True:
    bg.onscreenclick(detect_click)
    check_prase()
    loop()
    show_score()
    t.update()
    t.clear()

	

	
	
	
	
	
	
	
	